# Contributor: Matthew T Hoare <matthew.t.hoare@gmail.com>
# Maintainer: Matthew T Hoare <matthew.t.hoare@gmail.com>
pkgname=stone-soup
pkgver=0.32.1
pkgrel=0
pkgdesc="Open-source, single-player, role-playing roguelike game of exploration and treasure-hunting"
url="https://crawl.develz.org"
arch="all"
license="BSD-2-Clause AND BSD-3-Clause AND CC0-1.0 AND MIT AND Zlib AND Apache-2.0 AND BSL-1.0"
depends="mesa-dri-gallium font-dejavu"
makedepends="
	freetype-dev
	glu-dev
	lua5.1-dev
	mesa-dev
	ncurses-dev
	perl
	pngcrush
	py3-yaml
	python3
	sdl2-dev
	sdl2_image-dev
	sdl2_mixer-dev
	sqlite-dev
	"
options="!check" # no checks
source="$pkgname-$pkgver.tar.xz::https://github.com/crawl/crawl/releases/download/$pkgver/stone_soup-$pkgver-nodeps.tar.xz
	crawl.desktop
	crawl-tiles.desktop
	no-execinfo.patch
	root-owner.patch
	"
builddir="$srcdir/stone_soup-$pkgver"

prepare() {
	default_prepare

	# fix version
	git init .
	git config user.name a
	git config user.email 'a@a'
	git add .
	git commit -m "$pkgver"
	git tag $pkgver

	# create separate source directories for console and tiles versions
	cp -r source console
	cp -r source tiles
}

build() {
	# first build tiles version
	make -C tiles \
		DESTDIR="$pkgdir" \
		SAVEDIR="~/.crawl/" \
		DATADIR="/usr/share/$pkgname/data" \
		TILES=y \
		SOUND=y \
		EXTERNAL_LDFLAGS="$LDFLAGS" \
		prefix=/usr \
		bin_prefix=bin

	# then build console version
	make -C console \
		DESTDIR="$pkgdir" \
		SAVEDIR="~/.crawl/" \
		DATADIR="/usr/share/$pkgname/data" \
		SOUND=y \
		EXTERNAL_LDFLAGS="$LDFLAGS" \
		prefix=/usr \
		bin_prefix=bin
}

package() {
	# first install tiles version
	make -C tiles \
		DESTDIR="$pkgdir" \
		SAVEDIR="~/.crawl/" \
		DATADIR="/usr/share/$pkgname/data" \
		TILES=y \
		SOUND=y \
		EXTERNAL_LDFLAGS="$LDFLAGS" \
		prefix=/usr \
		bin_prefix=bin \
		install

	# rename tiles executable to avoid clashing with console crawl
	mv "$pkgdir"/usr/bin/crawl "$pkgdir"/usr/bin/crawl-tiles

	# now install console version
	make -C console \
		DESTDIR="$pkgdir" \
		SAVEDIR="~/.crawl/" \
		DATADIR="/usr/share/$pkgname/data" \
		SOUND=y \
		EXTERNAL_LDFLAGS="$LDFLAGS" \
		prefix=/usr \
		bin_prefix=bin \
		install

	# install icon and .desktop files
	install -Dm644 source/dat/tiles/stone_soup_icon-32x32.png \
		"$pkgdir"/usr/share/pixmaps/"$pkgname".png
	install -Dm644 "$srcdir"/crawl.desktop \
		"$pkgdir"/usr/share/applications/crawl.desktop
	install -Dm644 "$srcdir"/crawl-tiles.desktop \
		"$pkgdir"/usr/share/applications/crawl-tiles.desktop
}

sha512sums="
0e8b626874b118820397c69293245649ce886a418b56d63167a8c1d4d618cbb30ddd8bc0082b15060c1907ce547266517462d226f1ca29ab4220dda0ceb39646  stone-soup-0.32.1.tar.xz
8e14cfa97f8765126050b14dc85cee60a6f00fe458b21714a34403872fbfc11f7b1d42897424936fbaaba5ad0fed76c10a90c4c144076c9526f7e653c3dbbca0  crawl.desktop
d8c64f6c388f3551e6744b0fccfa0fc7148cb839174a5ed464fdb46511f8e0f4e66cb297f91446e5e098cbacddaba88476f499fb50e6c39e6563fe8231dafe54  crawl-tiles.desktop
3fbd434786edb456b27942cd1aa8034241359b701afadea73f54c3622b1ccaf6f7f3a1c01b8d0d3e8388baaed38b205c4013da35a00974848af5b27f6141c379  no-execinfo.patch
9b785d08e722a8fee4f1fb624b77110cfdaa6d74422d874d53a13064b1054463738aceb4a40c83a1c5932c07f76186f1136bb60c00ed96e10e225edcb4722636  root-owner.patch
"
